package com.zjw.hyphenateui.ui;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.havi.helper.ChatHelper;
import com.example.havi.util.ChatSPUtil;
import com.zjw.hyphenateui.R;
import com.zjw.hyphenateui.helper.UserHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class MineFragment extends BaseFragment {
    @BindView(R.id.nickName_tv)
    TextView nickNameTv;
    @BindView(R.id.chatId_tv)
    TextView chatIdTv;
    @BindView(R.id.loginOut_tv)
    TextView loginOutTv;
    Unbinder unbinder;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    protected void initView() {
        String nickName =  ChatSPUtil.getString("nickName", "");
        String chat_user =  ChatSPUtil.getString("chat_user", "");
        nickNameTv.setText(nickName);
        chatIdTv.setText(chat_user);
    }

    @OnClick(R.id.loginOut_tv)
    public void onViewClicked() {
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivityContext());
        builder.setTitle("提示");
        builder.setMessage("是否退出环信聊天");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                UserHelper.loginOut();
                startActivity(LoginActivity.class);
                finishActivity();
            }
        }).show();
    }
}
